<?php

namespace IDock\Insurance\DEMO\Response;

use IDock\Http\Response;

class AllDEMOResponse extends Response
{
    protected $records = [];

    protected $result = [];

    public function resolve(): Response
    {
        $body = $this->getBody();
        $body = json_decode($body, true);

        if ($this->printer and is_string($this->printer)) {
            $this->printer = new $this->printer;
        }

        $responseCode = $body['responseCode'] ?? '0';

        $errorMsg = $body['errorMsg'] ?? '';

        if (!$responseCode) {
            $this->setError($errorMsg);
            return $this;
        }

        $this->setBody($body ?? []);

        return $this;
    }
}
